package com.acce.gxsc.page.registerCar.addCarInfo;

import com.acce.gxsc.model.WorkModel;
import com.acce.gxsc.model.loaclBean.ResultBean;
import com.acce.gxsc.model.netBean.NetInCarListBean;
import com.acce.sdk.base.mvp.BasePresenter;
import com.acce.sdk.base.volleyHttp.GsonUtils;
import com.acce.sdk.utils.LogUtils;
import com.acce.sdk.utils.ToastUtils;

import rx.Subscriber;

/**
 * Created by huxley on 2017/5/26.
 */

public class AddCarInfoPresenter extends BasePresenter<AddCarInfoView> {

    public void getTime(String carNo2) {
        WorkModel.getInstance().getTime(carNo2, "").subscribe(new Subscriber<ResultBean<NetInCarListBean>>() {
            @Override
            public void onStart() {
                if (mViewRef != null) {
                    getView().showProgressDialog("保存中...", false);
                }
            }
            @Override
            public void onNext(ResultBean<NetInCarListBean> datas) {
                if (mViewRef != null) {
                    LogUtils.logout(GsonUtils.toJson(datas));
                    if (datas == null || datas.result == null || datas.result.inCarList == null || datas.result.inCarList.isEmpty()) {
                        getView().getTimeSuccess("");
                    } else {
                        getView().getTimeSuccess(datas.result.inCarList.get(0).createTime);
                    }

                }
            }
            @Override
            public void onCompleted() {
                if (mViewRef != null) {
                    getView().hideProgressDialog();
                }
            }
            @Override
            public void onError(Throwable e) {
                if (mViewRef != null) {
                    e.printStackTrace();
                    ToastUtils.show("删除失败！");
                    getView().hideProgressDialog();
                }
            }
        });
    }
}
